package cn.zc.kafkademo.producer;

import cn.zc.kafkademo.common.KafkaTopicConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 发送消息给 kafka 生产者
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class SendMessage {
    @Autowired
    private KafkaProducer kafkaProducer;

    @Value("${kafka.topic1}")
    private String topic1;

    @Test
    public void test() {
        int index = 0;
        while (index < 100) {
            kafkaProducer.sendMessage(topic1, "person","test" + index);
            //kafkaProducer.sendMessage(KafkaTopicConstants.MY_TOPIC2, "car","test" + index);
            index++;
        }
    }

}
